home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
United Public Domain Gold 4
/
United Public Domain Gold 4.iso
/
fredfish
/
ff.0164.dms
/
ff.0164.adf
/
Newton
/
strtok.c
< prev
Wrap
C/C++ Source or Header
|
1988-11-22
|
1KB
|
62 lines
/* strtok.c: 3 very useful string-handling functions.
* You don't need this file if you are using Lattice C.
* Manx C does not provide them.
*
* Written by Daniel Barrett. 100% PUBLIC DOMAIN. */
#include "decl.h"
#define STRING_END '\0'
/* Return the next string "token" in "buf". Tokens are substrings
* separated by any characters in "separators". */
char *strtok(buf, separators)
char *buf, *separators;
{
register char *token, *end; /* Start and end of token. */
extern char *strpbrk();
static char *fromLastTime;
if (token = buf ? buf : fromLastTime) {
token += strspn(token, separators); /* Find token! */
if (*token == STRING_END)
return(NULL);
fromLastTime = ((end = strpbrk(token,separators))
? &end[1]
: NULL);
*end = STRING_END; /* Cut it short! */
}
return(token);
}
/* Return a pointer to the first occurance in "str" of any character
* in "charset". */
char *strpbrk(str, charset)
register char *str, *charset;
{
extern char *index();
while (*str && (!index(charset, *str)))
str++;
return(*str ? str : NULL);
}
/* Return the number of characters from "charset" that are at the BEGINNING
* of string "str".
*/
int strspn(str, charset)
register char *str, *charset;
{
register char *s;
s = str;
while (index(charset, *s))
s++;
return(s - str);
}